<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class ask extends admin {
	function __construct() {
		parent::__construct();
		$this->db = pc_base::load_model('ask_model');
	}
	
	public function init() {
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$data = $this->db->listinfo($where,$order = 'id DESC',$page, $pages = '9');
		$pages = $this->db->pages;
		// print_r($data);	
		$big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=ask&c=ask&a=add\', title:\''.('查看问题').'\', width:\'700\', height:\'450\'}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);',"添加问答");
		include $this->admin_tpl('ask_list');
	}
	
	public function add() {
		
		include $this->admin_tpl('ask_add');
	}

	public function edit() {
		$id = intval($_GET['id']);
		if($id < 1) return false;

		if(isset($_POST['dosubmit'])) {
			if($_POST['ask']['ask'] == "暂无回复...") {
				showmessage('请填写回答内容...',HTTP_REFERER);
			}else {
				$_POST['ask']['a_time'] = SYS_TIME;
				$_POST['ask']['ask'] = safe_replace($_POST['ask']['ask']);
				$_POST['ask']['is_ask'] = intval(1);
			}
			
			$data = new_addslashes($_POST['ask']);
			
			$askid = $this->db->update($data,array('id'=>$id));

			if(!$askid) return FALSE; 
			showmessage('回答成功!',HTTP_REFERER);
		}else{
			$data = $this->db->get_one(array('id'=>$id));
			include $this->admin_tpl('ask_edit');
		}
		
	}

	public function delete() {
		$id = intval($_GET['id']);
		if($id < 1) return false;
		$result = $this->db->delete(array('id'=>$id));
		if(!$result) return false;
		showmessage('删除成功...','?m=ask&c=ask&a=init');
	}
}